<?php
//查询条件

namespace App\Repositories\Filter;

class CouponReceiveFilter
{

    /**
     * 处理查询条件
     * @param $query
     * @return array[]
     */
    public static function handleQuery($query = []) {
        $where = [];
        $whereIn = [];
        if (!empty($query['id'])) {
            $where[] = ['id', $query['id']];
        }
        if (!empty($query['ids'])) {
            $whereIn[] = ['id', $query['ids']];
        }
        if (!empty($query['coupon_id'])) {
            $where[] = ['coupon_id', $query['coupon_id']];
        }
        if (!empty($query['coupon_ids'])) {
            $whereIn[] = ['coupon_id', $query['coupon_ids']];
        }
        if (!empty($query['receiver_id'])) {
            $where[] = ['receiver_id', $query['receiver_id']];
        }
        if (!empty($query['receiver_ids'])) {
            $whereIn[] = ['receiver_id', $query['receiver_ids']];
        }
        if (!empty($query['openid'])) {
            $where[] = ['openid', $query['openid']];
        }
        if (!empty($query['openids'])) {
            $whereIn[] = ['openid', $query['openids']];
        }
        if (!empty($query['activity_id'])) {
            $where[] = ['activity_id', $query['activity_id']];
        }
        if (!empty($query['activity_ids'])) {
            $whereIn[] = ['activity_id', $query['activity_id']];
        }
        //领取时间
        if (!empty($query['receive_date_gte'])) {
            $where[] = ['receive_date', '>=', $query['receive_date_gte']];
        }
        if (!empty($query['receive_date_lt'])) {
            $where[] = ['receive_date', '<', $query['receive_date_lt']];
        }
        //核销状态
        if (!empty($query['consume_status'])) {
            $where[] = ['consume_status', $query['consume_status']];
        }
        //核销时间
        if (!empty($query['consume_date_gte'])) {
            $where[] = ['consume_date', '>=', $query['consume_date_gte']];
        }
        if (!empty($query['consume_date_lt'])) {
            $where[] = ['consume_date', '<', $query['consume_date_lt']];
        }
        if (!empty($query['coupon_end_date_lt'])) {
            $where[] = ['coupon_end_date', '<', $query['coupon_end_date_lt']];
        }

        return [
            'where' => $where,
            'whereIn' => $whereIn,

        ];
    }

}
